Skip to content

Comments

Improve error messages for failed command hooks#94

Merged
nhorton merged 5 commits intomainfrom
claude/improve-hook-error-messages-AF45e
Jan 21, 2026
Merged

Improve error messages for failed command hooks#94
nhorton merged 5 commits intomainfrom
claude/improve-hook-error-messages-AF45e

Conversation

@nhorton
Copy link
Contributor

@nhorton nhorton commented Jan 21, 2026

When a rule with a command hook fails, the error message now includes:

  • Rule name
  • The exact command that was executed
  • Exit code
  • Both stdout and stderr output (when present)
  • "(no output)" message when command produces no output

This replaces the previous minimal error format that only showed stderr.

claude and others added 5 commits January 21, 2026 16:11
When a rule with a command hook fails, the error message now includes:
- Rule name
- The exact command that was executed
- Exit code
- Both stdout and stderr output (when present)
- "(no output)" message when command produces no output

This replaces the previous minimal error format that only showed stderr.
When a hook script crashes (unhandled exception, import error, etc.),
it now outputs a proper JSON response with detailed error information
instead of causing a generic "Failed with non-blocking status code" error.

Changes:
- Add format_hook_error() and output_hook_error() to wrapper.py
- Wrap run_hook() in try/except to catch all errors
- Add comprehensive error handling in rules_check.py main()
- Add tests for error handling functionality

The error output includes:
- Error type and message
- Context (what operation was being performed)
- Full traceback for debugging
The try/except in main() was redundant since run_hook() in wrapper.py
already catches all exceptions during hook execution. Removed the
extra layer, keeping only the if __name__ fallback for early failures.
Ruff auto-fix removed local imports that were already imported at module level.
@nhorton nhorton merged commit 0ed743c into main Jan 21, 2026
4 checks passed
@nhorton nhorton deleted the claude/improve-hook-error-messages-AF45e branch January 21, 2026 17:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants